mean.r
(See Figure mean
does not do any error checking on the input
arguments. Whether it should or not is debatable. We will
present arguments for and against:
mean
with a string, or a list
variable as argument will result in a slightly obscure
error message.
> mean ( "string constant" ) rlab: NULL, invalid type for sum() near line 25, file: /usr/local/lib/rlab/rlib/mean.r > mean ( << [1,2,3]; 100 >> ) rlab: NULL, invalid type for sum() near line 25, file: /usr/local/lib/rlab/rlib/mean.r >Instead of
mean
reporting the error, the error is
propagated down to sum
. This is somewhat confusing,
since the user committed the error with the function
mean
.
mean
will work just
fine. Users who are foolish enough to try and compute the
mean value of a string, or a heterogeneous object (a list)
should not be catered to. That is, users who use the
function correctly, should not have to pay a performance
penalty.